<?php
/**
 * Created by PhpStorm.
 * User: liuxiaojie
 * Date: 2019-04-29
 * Time: 17:46
 */

namespace app\repair\controller;

use app\common\BaseLoginCustomer;
use app\model\RepairOrder;
use app\service\RepairService;
use think\Request;

class Repair extends BaseLoginCustomer
{
    private $repairService;
    function __construct(Request $request = null, RepairService $repairService)
    {
        parent::__construct($request);
        $this->repairService = $repairService;
    }

    function myCount()
    {
        $param = [
            'customer_id'=> $this->userInfo['id']
        ];
        $data = $this->repairService->count($param);
        return success($data);
    }

    function evaList()
    {
        $param = [
            'a.customer_id'=> $this->getParam('master_id', 0)
        ];

        $data = $this->repairService->eavList($param);
        return success($data);
    }

    function masterInfo()
    {
        $master_id = $this->getParam('master_id', 0);
        $data = $this->repairService->masterInfo($master_id);
        return success($data);
    }

    function masterList()
    {
        $service_id = $this->getParam('service_type', 0);
        $param = [
            'service_type'=> ['like', "%$service_id%"]
        ];
        $data = $this->repairService->masterList($param);
        return success($data);
    }

    function editAvatar()
    {
        $file = request()->file('image');

        // 移动到框架应用根目录/public/uploads/ 目录下
        if($file){
            $info = $file->validate(['size'=>2097152])->move(ROOT_PATH . 'public' . DS . 'uploads');
            if($info){
                // 成功上传后 获取上传信息
                // 输出 jpg
                $url = DS . 'uploads'.DS.$info->getSaveName();
            }else{
                // 上传失败获取错误信息
                return fail();
            }
        }else{
            return fail();
        }
        $url = config('host').$url;
        db('repair_person')->where(['customer_id'=> $this->userInfo['id']])->update(['avatar'=> $url]);

        return success(['url'=> $url]);
    }


}